<template>
  <div class="order-container">
    <div class="order-over-view">
      <div class="over-view-list">
        <div class="list-item">
          <div class="count" @click="handleChange('deal')">{{ count.daiBan || 0 }}</div>
          <div class="title">待办</div>
        </div>
        <div class="list-item">
          <div class="count" @click="handleChange('complete')">{{ count.finishNum || 0 }}</div>
          <div class="title">已办</div>
        </div>
        <div class="list-item">
          <div class="count" @click="handleChange('my')">{{ Number(count.draftNum) + Number(count.hasNum) || 0 }}</div>
          <div class="title">我的</div>
        </div>
      </div>
      <div class="order-add">
        <van-button round size="small" @click="handleAdd">新建工单</van-button>
      </div>
    </div>
    <deal-order ref="dealRef" v-if="active == 'deal'" />
    <complete-order ref="completeRef" v-if="active == 'complete'" />
    <my-order ref="myRef" v-if="active == 'my'" @upload="getCount" />
  </div>
</template>

<script>
import completeOrder from '@/views/components/order/complete.vue'
import dealOrder from '@/views/components/order/deal.vue'
import myOrder from '@/views/components/order/my.vue'
import { orderCount } from '@/api/order.js'

export default {
  components: { completeOrder, dealOrder, myOrder },
  data() {
    return {
      active: 'deal',
      count: {}
    }
  },
  mounted() {
    this.getCount()
    this.handleChange(this.active)
  },
  methods: {
    handleChange(val) {
      this.active = val
      this.$nextTick(() => {
        this.$refs[`${val}Ref`].loadData(true)
      })
    },
    handleAdd() {
      this.$open.call(this, '/order/add')
    },
    async getCount() {
      const res = await orderCount({})
      const { success, result } = res
      if(success) {
        this.count = result
      }
    }
  }
}
</script>
<style lang="less" scoped>
.order-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  .order-over-view {
    background: #4D98FF;
    color: #fff;
    border-radius: 4px;
    margin: 8px;
    padding: 16px;
    height: 94px;
  }
  .over-view-list {
    display: flex;
    align-items: center;
    justify-content: space-around;
    text-align: center;
    margin-bottom: 16px;
    .count {
      font-size: 18px;
      font-weight: 700;
      margin-bottom: 4px;
    }
  }
  .order-add {
    text-align: center;
    .van-button {
      padding: 0 16px;
      color: #4D98FF;
      font-weight: 500;
    }
  }
}
</style>
